#include "stdafx.h"
#include "InspectorWnd.h"
#include "GuiPlugin.h"
#include "ResourceManager.h"


CInspectorWnd::CInspectorWnd()
{
}

CInspectorWnd::~CInspectorWnd()
{
	SafeRelease(mpTransformWnd);
}

void CInspectorWnd::initWnd()
{
	mini::ui::CGuiPlugin* pGuiPlugin = mini::GETPLUGIN(mini::ui::CGuiPlugin, mini::PluginType::GUI);
	mpTransformWnd = new CTransformWnd();
	pGuiPlugin->initWnd(mpTransformWnd, "resource/Editor/Gui/TransformWnd.xml");
	addChildWnd(mpTransformWnd);
	CWnd::setTimer(0, 500, nullptr);
}

void CInspectorWnd::setPickActor(mini::CActor* pActor)
{
	if (nullptr != pActor)
	{
		if (nullptr != mpPickActor)
		{
			mpPickActor->hideBoundBox();
		}
		mpPickActor = pActor;
	}
}

void CInspectorWnd::cancelPickActor()
{
	auto poitionX = mpTransformWnd->findChildWnd("pX");
	auto poitionY = mpTransformWnd->findChildWnd("pY");
	auto poitionZ = mpTransformWnd->findChildWnd("pZ");

	auto rotationX = mpTransformWnd->findChildWnd("rX");
	auto rotationY = mpTransformWnd->findChildWnd("rY");
	auto rotationZ = mpTransformWnd->findChildWnd("rZ");

	auto scaleX = mpTransformWnd->findChildWnd("sX");
	auto scaleY = mpTransformWnd->findChildWnd("sY");
	auto scaleZ = mpTransformWnd->findChildWnd("sZ");

	if (nullptr != mpPickActor)
	{
		mpPickActor->getBoundBox().hide();
		mpPickActor = nullptr;
		poitionX->setWindowText("0");
		poitionY->setWindowText("0");
		poitionZ->setWindowText("0");


		rotationX->setWindowText("0");
		rotationY->setWindowText("0");
		rotationZ->setWindowText("0");

		scaleX->setWindowText("0");
		scaleY->setWindowText("0");
		scaleZ->setWindowText("0");
	}
}

void CInspectorWnd::bindMsg()
{
}

bool CInspectorWnd::create()
{
	return true;
}

void CInspectorWnd::onTimer(int id, void* parameters)
{
	switch (id)
	{
	case 0:
	{
		if (nullptr == mpTransformWnd || nullptr == mpPickActor)
		{
			return;
		}
		auto poitionX = mpTransformWnd->findChildWnd("pX");
		auto poitionY = mpTransformWnd->findChildWnd("pY");
		auto poitionZ = mpTransformWnd->findChildWnd("pZ");

		auto rotationX = mpTransformWnd->findChildWnd("rX");
		auto rotationY = mpTransformWnd->findChildWnd("rY");
		auto rotationZ = mpTransformWnd->findChildWnd("rZ");

		auto scaleX = mpTransformWnd->findChildWnd("sX");
		auto scaleY = mpTransformWnd->findChildWnd("sY");
		auto scaleZ = mpTransformWnd->findChildWnd("sZ");

		mpPickActor->showBoundBox();

		{
			auto value = mpPickActor->getPosition();
			poitionX->setWindowText(std::to_string(value.x));
			poitionY->setWindowText(std::to_string(value.y));
			poitionZ->setWindowText(std::to_string(value.z));
		}
		{
			auto value = mpPickActor->getRotation();
			rotationX->setWindowText(std::to_string(value.x));
			rotationY->setWindowText(std::to_string(value.y));
			rotationZ->setWindowText(std::to_string(value.z));
		}
		{

			auto value = mpPickActor->getScale();
			scaleX->setWindowText(std::to_string(value.x));
			scaleY->setWindowText(std::to_string(value.y));
			scaleZ->setWindowText(std::to_string(value.z));
		}


	}

	default:
		break;
	}
}


